﻿using MediatR;
using W.Purchase.API.Application.Command;
using W.Purchase.Domain;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler
{
    public class SalesOrderReturnCommandHandler : IRequestHandler<SalesOrderReturnCommand, int>
    {
        private readonly ISaleReturnsReposiotry saleReturnsReposiotry;

        private readonly ISalesOrdersRepository salesOrdersRepository;

        private readonly IProductSalesReturnsRepository productSalesReturnsRepository;

        private readonly IProductsSalesRepository productsSalesRepository;

        public SalesOrderReturnCommandHandler(ISaleReturnsReposiotry saleReturnsReposiotry, ISalesOrdersRepository salesOrdersRepository, IProductSalesReturnsRepository productSalesReturnsRepository, IProductsSalesRepository productsSalesRepository)
        {
            this.saleReturnsReposiotry = saleReturnsReposiotry;
            this.salesOrdersRepository = salesOrdersRepository;
            this.productSalesReturnsRepository = productSalesReturnsRepository;
            this.productsSalesRepository = productsSalesRepository;
        }

        public async Task<int> Handle(SalesOrderReturnCommand request, CancellationToken cancellationToken)
        {
            var listOrder = await salesOrdersRepository.GetAsync(w=>w.SalesOrdersId == request.SalesOrdersId);

            var listProduct = await productsSalesRepository.GetAsync(w => w.SalesOrdersId == request.SalesOrdersId);

           SaleReturns saleReturns = new SaleReturns();
            saleReturns.SaleReturnsNo = listOrder.FirstOrDefault().SalesOrdersNo;
            saleReturns.ProductName = listProduct.FirstOrDefault().ProductName;
            saleReturns.ProductNo = listProduct.FirstOrDefault().ProductNo;
            saleReturns.ProductSpec = listProduct.FirstOrDefault().ProductSpec;
            saleReturns.UnitName = listProduct.FirstOrDefault().UnitName;
            saleReturns.Price = listProduct.FirstOrDefault().Price;
            saleReturns.SaleReturnsNum = listProduct.FirstOrDefault().SaleReturnsNum;
            saleReturns.UnitName = listProduct.FirstOrDefault().UnitName;
            throw new NotImplementedException();
        }
    }
}
